from Tkinter import *
from tkSimpleDialog import *

class ProjectFrame(Frame):
    """
    Represents the frame that provides a user interface to access project information.
    """
    
    def __init__(self, parentControl, listener):
        Frame.__init__(self, parentControl)
        self.parentControl = parentControl
        self.listener = listener
        
        label = Label(self, text="Nom du projet:")
        label.pack()
        
        self.nameTextBox = Text(self, width=20, height=1)
        self.nameTextBox.pack()
        
        label = Label(self, text="Description: ")
        label.pack()
        
        self.summaryTextBox = Text(self, width=40, height=15)
        self.summaryTextBox.pack()
        
        label = Label(self, text="Mandat: ")
        label.pack()
        
        self.mandateTextBox = Text(self, width=40, height=15)
        self.mandateTextBox.pack()
        
        button = Button(self, text="Sauvegarder", command=self._onSavePressed)
        button.pack()
        
    def setName(self, name):
        self.nameTextBox.delete(1.0, END)
        self.nameTextBox.insert(END, name)
        
    def setSummary(self, summary):
        self.summaryTextBox.delete(1.0, END)
        self.summaryTextBox.insert(END, summary)
        
    def setMandate(self, mandate):
        self.mandateTextBox.delete(1.0, END)
        self.mandateTextBox.insert(END, mandate)
        
    def _onSavePressed(self):
        name = self.nameTextBox.get(1.0, END).strip()
        summary = self.summaryTextBox.get(1.0, END).strip()
        mandate = self.mandateTextBox.get(1.0, END).strip()
        self.listener.onSaveProjectChanges(name, summary, mandate)